package com.ht.oss.dto;

import io.swagger.annotations.ApiModel;
import lombok.Getter;

@Getter
@ApiModel("RestApi返回数据")
public class ResData<T> {
    private String msg;
    private boolean success;
    private T data;

    private ResData() {}

    public static <D> ResData<D> success() {
        return success(null, null);
    }

    public static <D> ResData<D> success(String msg) {
        return success(msg, null);
    }

    public static <D> ResData<D> success(D data) {
        return success(null, data);
    }

    public static <D> ResData<D> success(String msg, D data) {
        ResData<D> res = new ResData<>();
        res.data = data;
        res.msg = msg;
        res.success = true;
        return res;
    }

    public static <D> ResData<D> fail(String msg) {
        return fail(msg, null);
    }

    public static <D> ResData<D> fail(String msg, D data) {
        ResData<D> res = new ResData<>();
        res.data = data;
        res.msg = msg;
        res.success = false;
        return res;
    }
}
